package com.cn.zpark;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebInitParam;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @PackageName: com.cn.zpark
 * @ClassName: ServletConfigDemo02
 * @Description:
 * @author: RZS
 * @date: 2022/4/6  17:26
 */
@WebServlet(value = "/sc2.do", initParams = {
        @WebInitParam(name = "uname", value = "李四"),
        @WebInitParam(name = "pwd", value = "888888")
})
public class ServletConfigDemo02 extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 获取初始化参数
        String uname = this.getServletConfig().getInitParameter("uname");
        String pwd = this.getServletConfig().getInitParameter("pwd");
        System.out.println(uname + ": " + pwd);
    }
}
